package internal

import (
	"game-server/log"
	"game-server/msg"
	"game-server/conf"
)

func init() {
	skeleton.RegisterChanRPC("AcceptBattle", rpcNewAgent)
	skeleton.RegisterChanRPC("CheckUser", rpcCloseAgent)
	skeleton.RegisterChanRPC("UpdateName", rpcUpdateName)
	skeleton.RegisterChanRPC("UpdateBird", rpcUpdateBird)
	skeleton.RegisterChanRPC("RankGolden", rpcRankGolden)
	skeleton.RegisterChanRPC("UpdateGolden", rpcUpGolden)
	skeleton.RegisterChanRPC("UpdateUser", rpcUpdateUser)
}

func rpcNewAgent(args []interface{}) {

}


func rpcUpdateUser(args []interface{})interface{} {
	log.Debug("rpcNewAgent: args = ", args)
	infos := args[0].([]int32)
	playerId := infos[0]
	log.Debug("playerId",playerId)
	updateUawe(playerId)
	return args
}

func rpcCloseAgent(args []interface{}) interface{} {
	userinfo := getUser(args)
	log.Debug("ChanRPC: userinfo = ", userinfo)
	return userinfo
}
func rpcRankGolden(args []interface{}) interface{} {
	uinList := getRankGolden(args)
	log.Debug("ChanRPC: uinList = ", uinList)
	return uinList
}

func rpcUpdateName(args []interface{}) interface{} {
	log.Debug("rpcUpdateName: args = ", args)
	MsgChangeName := args[0].(*msg.MsgChangeName)
	log.Debug("rpcUpdateName: MsgChangeName = ", MsgChangeName)
	playerId := MsgChangeName.GetPlayerId()
	name := MsgChangeName.GetName()
	updateName(playerId, name)
	updateNameNum(playerId, 1)
	return args
}

func rpcUpdateBird(args []interface{}) interface{}{
	log.Debug("rpcUpdateName: args = ", args)
	MsgChangeName := args[0].(*msg.MsgChangeBird)
	log.Debug("rpcUpdateName: MsgChangeName = ", MsgChangeName)
	playerId := MsgChangeName.GetPlayerId()
	birdid := MsgChangeName.GetBirdId()
	updateBird(playerId,birdid )
	updateBirdNum(playerId, 1)
	return args
}

func rpcUpGolden(args []interface{}) interface{}{
	log.Debug("rpcUpGolden: args = ", args)
	infos := args[0].([]int32)
	playerId := infos[0]
	golden := infos[1]
	log.Debug("rpcUpdateName: playerId = ", playerId)
	log.Debug("rpcUpdateName: golden = ", golden)

	updateGolden(playerId -conf.Server.BaseNum,golden)
	return args
}

